#include "CClientSocket.h"

int CSocket::SendAsyn(IN NET_PACKET_HEADER* pHeader)
{
    if (!pHeader) return 0;

    int nRetLen = 0;
    int nLen = pHeader->nDataLength;
    char* pSendData = (char*)pHeader;

    if (m_SendBuff.Append(pSendData, nLen))
        nRetLen = nLen;

    return nRetLen;
}

BOOL CSocket::isFullMsg()
{
    if (m_RecvBuff.GetEndPos() >= sizeof(NET_PACKET_HEADER))
    {
        NET_PACKET_HEADER* Header = (NET_PACKET_HEADER*)m_RecvBuff.GetBuff();
        return (m_RecvBuff.GetEndPos() >= (UINT)(Header->nDataLength));
    }
    return FALSE;
}

BOOL CSocket::RemoveHeadMsg()
{
    if (!isFullMsg()) return FALSE;

    NET_PACKET_HEADER* Packet = (NET_PACKET_HEADER*)(m_RecvBuff.GetBuff());
    UINT nStartPos = (UINT)(Packet->nDataLength);
    UINT nRestLen = m_RecvBuff.GetEndPos() - nStartPos;

    memcpy(m_RecvBuff.GetBuff(), m_RecvBuff.GetBuff() + nStartPos, nRestLen);
    m_RecvBuff.RetreatEndPos(nStartPos);

    return TRUE;
}